//
//  TGTrendListCollectionReusableView.m
//  WanCaiC8
//
//  Created by QiuXun on 2019/1/18.
//  Copyright © 2019 tangang. All rights reserved.
//

#import "TGTrendListCollectionReusableView.h"

@interface TGTrendListCollectionReusableView ()

@property(nonatomic,strong)UIImageView *icon;
@property(nonatomic,strong)UILabel *titleLabel;


///切换频道
@property(nonatomic,strong)UIButton *chaneButton;

///切换频道
@property(nonatomic,strong)UIView *lineView;
@end


@implementation TGTrendListCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{
    
    
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:self.lineView];

    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(0);
    }];
    self.lineView.hidden = YES;
    
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    [self addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(self.lineView.mas_bottom);
    }];
    
    
    
    self.icon = [[UIImageView alloc] init];
    [bgView addSubview:self.icon];
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(10);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    
    
    self.titleLabel = [UILabel tg_labelWithText:@"" fontSize:13 color:DEFAULTTEXTCOLOR];
    [bgView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.icon.mas_right).offset(10);
    }];
    
    
    
    self.chaneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    NSAttributedString *attStr =[NSAttributedString tg_RightImageTextWithImage:[UIImage imageNamed:@"tgdown"] imageW:12 imageH:7 leftTitle:@"切换彩种" fontSize:13 titleColor:DEFAULTTEXTCOLOR spacing:8];
    [self.chaneButton setAttributedTitle:attStr forState:UIControlStateNormal];
    [self.chaneButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.chaneButton.selected = NO;
    
    [bgView addSubview:self.chaneButton];
    
    [self.chaneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bgView);
        make.right.equalTo(bgView).offset(-10);
    }];
    
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = DEFAULTLINECOLOR;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.mas_equalTo(@.7);
    }];
    
}
-(void)setTitle:(NSString *)title{
    
    self.titleLabel.text = title;
    
}
-(void)setIconUrl:(NSString *)iconUrl{
    
    
    [self.icon sd_setImageWithURL:[NSURL URLWithString:iconUrl] placeholderImage:[UIImage imageNamed:@"chat_icon"]];
    
}
-(void)setIsHiddenChane:(BOOL)isHiddenChane{
    
    self.chaneButton.hidden = isHiddenChane;
    
}
-(void)setIsHiddenLineView:(BOOL)isHiddenLineView{
    
    if (isHiddenLineView) {
        [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        self.lineView.hidden = YES;
        
    }else{
        [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(5);
        }];
        self.lineView.hidden = NO;
    }
}

-(void)buttonClick:(UIButton *)button{
    
    
    
    if (self.chaneBlock) {
        self.chaneBlock();
    }
  
    
}
@end
 
